﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Site.Master" AutoEventWireup="true" CodeBehind="Clients.aspx.cs" Inherits="Legazpi.Payroll.Web.Admin.Clients" %>
<%@ Import Namespace="Emz.Core.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
    Client = {
        SectorPopupId: 0,
        ClientUrl: '<%=ResolveUrl("~/Admin/Clients.aspx/")%>'
    };    
    $(document).ready(function () {

        $('#<%=Submit.ClientID %>').click(function () {
            if (!$("#mainForm").valid()) {
                return false;
            }
        });

        $.validator.addMethod('validNumber', function (value, element) {
            var floatRegex = '[-+]?([0-9]*\.[0-9]+|[0-9]+)';
            return (value.match(floatRegex));
        }, 'Not accept non-numeric');

        $("#mainForm").validate({
            rules: {
                <%=ClientCode.Name%>: "required",
                <%=RegOT.Name%>: {
                    validNumber: true
                },
                <%=SpecialOT.Name%>: {
                    validNumber: true
                },
                <%=LegalHoliday.Name%>: {
                    validNumber: true
                },
                <%=SpecialHoliday.Name%>: {
                    validNumber: true
                },
                <%=NightDiff.Name%>: {
                    validNumber: true
                },
            },
            messages: {
                <%=ClientCode.Name%>: "Please enter Code"
            }
        });

        var clientId = <%= Model.Id%>;
        
        $('#btnAddSector').click(function (e) {
            e.preventDefault();            
            Client.SectorPopupId = $(this).attr("id");
            if(clientId == 0)
            {
                alert('Must save Client first!');
                return;
            }
            PopUpDialog.UrlDialog("Sector", 420, 480, true, '<%=ResolveUrl("~/PopupBoxes/SectorDialogBox.aspx/")%>?id=0&cid' + clientId, Client.SectorPopupId);
        });
        $('.btnEditSector').click(function (e) {
            e.preventDefault();
            var id = $(this).attr("id");
            Client.SectorPopupId = $(this).attr("id");
            PopUpDialog.UrlDialog("Sector", 420, 500, true, '<%=ResolveUrl("~/PopupBoxes/SectorDialogBox.aspx/")%>?id=' + id +'&cid' + clientId, Client.SectorPopupId );
        });

    });
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

        <label>Selected Client:</label> 
        <asp:DropDownList ID="ClientDropdown" runat="server" name="ClientDropdown"  AutoPostBack="true"
            AppendDataBoundItems="true" 
            onselectedindexchanged="ClientDropdown_SelectedIndexChanged">
            <asp:ListItem Text="--Select--" Value="0" /> 
        </asp:DropDownList>
        <br />
        <input type="hidden" runat="server" id="Id" />
        <fieldset class="register">
            <legend>Client Details</legend>
            <asp:Literal ID="literalNotification" runat="server" ></asp:Literal>
            <p>
                <label for="ClientCode">Code Label:</label>
                <input type="text" id="ClientCode"  class="textEntry" runat="server" />
            </p>
            <p>
                <label for="FirmName">Firm Name:</label>
                <input type="text" id="FirmName" maxlength="100" class="textEntry" runat="server" />
            </p>
            <p>
                <label for="FirmName">Contact No:</label>
                <input type="text" id="Contact" maxlength="100" class="textEntry" runat="server" />
            </p>
            <p>
                <label for="Address">Address:</label>
                <textarea id="Address" class="textEntry" rows="1" cols="40" runat="server" >                        
                </textarea>                    
            </p>                   
            <p style="float:left">
                <label>Regular Overtime:</label>
                <input type="text" id="RegOT" runat="server" class="inputNum" />
            </p>
            <p style="float:left">
                <label>Special Overtime:</label>
                <input type="text" id="SpecialOT" runat="server" class="inputNum" />
            </p>
            <p style="float:left">
                <label>Legal Holiday:</label>
                <input type="text" id="LegalHoliday" runat="server" class="inputNum" />
            </p>
            <p style="float:left">
                <label>Special Holiday:</label>
                <input type="text" id="SpecialHoliday" runat="server" class="inputNum" />
            </p>
            <p style="float:left">
                <label>Night Differential:</label>
                <input type="text" id="NightDiff" runat="server" class="inputNum" />
            </p>  
            <br style="clear:both" />
            <p>
                <a href="#" id="btnAddSector">add sector</a>
            </p>
            <asp:Repeater ID="repeater" runat="server">
                <HeaderTemplate>
                    
                    <table id="Sectortbl" cellpadding="1" cellspacing="0" 
                        border="0" class="display">
                      <thead>
                        <tr>                            
                            <th align="left">Sector</th>
                            <th align="left">Position</th>
                            <th align="left">Work Hours</th>
                            <th align="left">Rate/Day</th>
                            <th align="left">Rate/Hour</th>
                            <th align="left"></th>
                        </tr>
                      </thead>
                    <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>                      
                      <td><%# Eval("Name")%></td>
                      <td><%# (Position)Eval("Position") != null ? ((Position)Eval("Position")).Code : string.Empty %></td>
                      <td><%# Eval("WorkHours")%></td>
                      <td><%# Eval("RatePerDay")%></td>
                      <td><%# Eval("RatePerHour")%></td>                      
                      <td>
                        <a href="#" class="btnEditSector" id="<%# Eval("Id") %>">edit</a>
                      </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                        </tbody>
                    </table>
                </FooterTemplate>
            </asp:Repeater>                         
        </fieldset>
        <p class="submitButton">
            <asp:Button ID="Submit" runat="server" Text="Save" onclick="Submit_Click" />
        </p>

</asp:Content>
